//
//  PreferViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/9/28.
//  Copyright © 2020 吴欧. All rights reserved.
//

#import "PreferViewController.h"
#import "HEHotKeyModel.h"
#import "HEHotRecomCell.h"
#import "ULBCollectionViewFlowLayout.h"
#import "HEGoodsModel.h"
#import "HEGoodsDetailsViewController.h"
#import "HECartView.h"
#import "HEGoodSearchViewController.h"
#import "HEOneCategViewController.h"
#import "HEAllCategViewController.h"
#import "HEGoodSearchViewController.h"
#import "HECartDataModel.h"
#import "HECartViewController.h"


static NSString * const CellHotRecomId = @"HEHotRecomCell";
static NSString * const SupplementaryViewHeaderIdentify = @"SupplementaryViewHeaderIdentify";

@interface PreferViewController ()<QMUITextFieldDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSMutableArray <HEHotKeyModel *> *hotKeys;

@property (nonatomic, strong) UIView *hotView;
@property (nonatomic, strong) UIScrollView *hotScrollView;

@property (nonatomic, strong) UILabel *hotLb;
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray <HEGoodsModel *> * goodsArr;

@property (nonatomic, assign) BOOL hasCreateHead;
@property (nonatomic, strong) NSString *drugsUrl;
@property (nonatomic, strong) HECartView *cartView;

@end

@implementation PreferViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadCartData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.zx_navStatusBarStyle = ZXNavStatusBarStyleLight;
    
    [self initUI];
    [self loadHotKey];

    [self initConllectionView];

    [self loadGoodsData];
    [self loadDrugsUrl];

    
    // 购物车
    HECartView *cartView = [HECartView new];
    [self.view addSubview:cartView];
    [self.view bringSubviewToFront:cartView];
    _cartView = cartView;

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toCartClick)];
    [cartView addGestureRecognizer:tap];

    [cartView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.bottom.equalTo(self.view).mas_offset(-43);
         make.right.equalTo(self.view).mas_offset(0);
         make.width.height.mas_offset(83);
    }];
}

- (void)toCartClick {
    HECartViewController *vc = [HECartViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

 
- (void)initUI {
    
    self.view.backgroundColor = KHexColor(@"F8F8F8");
    
    // 输入框
    QMUITextField *searchTF = [[QMUITextField alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth-60, 34)];

    searchTF.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    searchTF.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    searchTF.layer.shadowOffset = CGSizeMake(0,5);
    searchTF.layer.shadowOpacity = 1;
    searchTF.layer.shadowRadius = 6;
    searchTF.layer.cornerRadius = 17;
    searchTF.font = DYFont(16);
    
    searchTF.placeholder = @"搜索一下";
    searchTF.placeholderColor = [UIColor colorWithHexString:@"#AAAAAA"];
    searchTF.delegate = self;
    
    UIView *leftWarp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 49, 18)];
    UIImageView *leftIcon = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"home_search")];
    leftIcon.frame = CGRectMake(20, 0, 18, 18);
    [leftWarp addSubview:leftIcon];
    searchTF.leftViewMode = UITextFieldViewModeAlways;
    searchTF.leftView = leftWarp;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchClickhandler)];
    [searchTF addGestureRecognizer:tap];
//    self.navigationItem.titleView = searchTF;
    
    UIView *titleWarp = [UIView new];
    [titleWarp addSubview:searchTF];
    [searchTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(titleWarp);
        make.width.mas_offset(KScreenWidth-60);
        make.height.mas_offset(34);
    }];

    [self zx_addCustomTitleView:titleWarp];
    self.zx_navBarBackgroundColor = CNavBgColor;
    self.zx_navLineViewBackgroundColor = CNavBgColor;


    // 热搜
    _hotView = [UIView new];
    _hotView.backgroundColor = CNavBgColor;
    [self.view addSubview:_hotView];
    
    UIImageView *backView = [UIImageView new];
    [_hotView addSubview:backView];
    backView.image = IMAGE_NAMED(@"home_title");
    
    backView.sd_layout
    .topSpaceToView(_hotView, 0)
    .rightEqualToView(_hotView)
    .leftEqualToView(_hotView)
    .heightIs(97);
    
    _hotLb = [UILabel new];
    _hotLb.text = @"热搜";
    _hotLb.textColor = KWhiteColor;
    _hotLb.font = DYBlodFont(18);
    [_hotView addSubview:_hotLb];
    
    [_hotView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).mas_offset(ZXNavBarHeight);
        make.right.left.equalTo(self.view);
        make.height.equalTo(@47);
    }];
    
    [_hotLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_hotView);
        make.left.equalTo(_hotView).mas_offset(15);
    }];
}

- (void)initHotView {
    
    [_hotScrollView removeAllSubviews];
    UIScrollView *manContent = [[UIScrollView alloc] init];
    manContent.scrollEnabled = YES;
    manContent.showsVerticalScrollIndicator = NO;
    manContent.showsHorizontalScrollIndicator = NO;
    [_hotView addSubview:manContent];
    _hotScrollView = manContent;

    manContent.sd_layout
    .centerYEqualToView(_hotView)
    .rightSpaceToView(_hotView, 5)
    .leftSpaceToView(_hotLb, 10)
    .heightIs(47);
            
    NSMutableArray *manArr = [NSMutableArray array];
    for (int i = 0; i < self.hotKeys.count; i++) {
        
        HEHotKeyModel *model = self.hotKeys[i];
        CGFloat w = [model.keyword widthForFont:DYFont(14)] + 20;
        CGFloat h = [model.keyword heightForFont:DYFont(14) width:w] + 10;

        QMUIFillButton *btn = [[QMUIFillButton alloc] initWithFrame:CGRectMake(w * i, 0, w, 28)];
        [btn setTitle:model.keyword forState:UIControlStateNormal];
        btn.titleLabel.font = DYFont(14);
        btn.fillColor = KHexColor(@"5F99F3");
        [manContent addSubview:btn];
        [manArr addObject:btn];
        btn.tag = i;
        [btn addTarget:self action:@selector(hotClick:) forControlEvents:UIControlEventTouchUpInside];

        if(i == 0) {
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(manContent);
                make.left.equalTo(manContent.mas_left).mas_offset(0);
                make.width.mas_offset(w);
                make.height.mas_offset(h);
            }];
        }else {
            QMUIFillButton *lastBtn = manArr[i-1];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(manContent);
                make.left.equalTo(lastBtn.mas_right).mas_offset(10);
                make.width.mas_offset(w);
                make.height.mas_offset(h);
            }];
        }
    }
        
    // 设置scrollview conetsize
    [manContent setupAutoContentSizeWithRightView:manArr.lastObject rightMargin:0];
}

- (void)hotClick:(id)sender {
    UIButton *btn = (UIButton *)sender;
    NSInteger tag = btn.tag;
    
    HEGoodSearchViewController *vc = [[HEGoodSearchViewController alloc] init];
    vc.keyword = self.hotKeys[tag].keyword;
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)serverClick:(id)sender {
    UIButton *btn = (UIButton *)sender;
    NSInteger tag = btn.tag;
    
    switch (tag) {
        case 21:
            {
                HEOneCategViewController *vc = [HEOneCategViewController new];
                vc.categID = 1036025;
                vc.title = @"居家照料";
                vc.channelType = HEChannelTypeHomeCare;
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
        case 22:
        {
            HEOneCategViewController *vc = [HEOneCategViewController new];
            vc.categID = 1036026;
            vc.title = @"健康服务";
            [self.navigationController pushViewController:vc animated:YES];
        }
        break;
        case 25: {
//           NSString * fileUrl = [[NSBundle mainBundle]pathForResource:_drugsUrl ofType:@"html"];
            NSURL * file = [NSURL URLWithString:_drugsUrl];

            RootWebViewController *webView = [[RootWebViewController alloc] initWithUrl:file.absoluteString];
            webView.isShowCloseBtn = YES;
            webView.title = @"医药上门";
            webView.showPageTitle = NO;
            webView.header = @{@"Referer":@"https://pay.miaoshou.com"}.mutableCopy;

            [self.navigationController pushViewController:webView animated:YES];
        }
        break;
        case 27:
        {
            HEAllCategViewController *vc = [HEAllCategViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        break;
            
        default:
            [Dialog toast:@"建设中，敬请期待~" delay:2.0];
            break;
    }
    
}

- (void)initHeadView:( UICollectionReusableView *)supplementaryView {
    _hasCreateHead = YES;
    // 私人医生
    UIImageView *banner = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"home_banner")];
    banner.contentMode = UIViewContentModeScaleAspectFill;
    banner.layer.cornerRadius = 10;
    banner.layer.masksToBounds = YES;
    banner.clipsToBounds = YES;
    [supplementaryView addSubview:banner];
    
    banner.sd_layout
    .topSpaceToView(supplementaryView, 5)
    .leftSpaceToView(supplementaryView, 15)
    .rightSpaceToView(supplementaryView, 15)
    .heightIs(80);
    
    UIView *contentView = [UIView new];
    contentView.backgroundColor = KHexColor(@"F8F8F8");
    [supplementaryView addSubview:contentView];
    
    contentView.sd_layout
    .topSpaceToView(banner, 2)
    .rightEqualToView(supplementaryView)
    .leftEqualToView(supplementaryView)
    .autoHeightRatio(0);
    
    // 服务宫格
    UIView *itemWarp = [UIView new];
    itemWarp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    itemWarp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    itemWarp.layer.shadowOffset = CGSizeMake(0,5);
    itemWarp.layer.shadowOpacity = 1;
    itemWarp.layer.shadowRadius = 6;
    itemWarp.layer.cornerRadius = 6;
    [contentView addSubview:itemWarp];
    
    UIView *serviceWarp = [UIView new];
    [itemWarp addSubview:serviceWarp];
    
    NSArray *itemImgList = @[@{@"name":@"体检服务", @"icon":@"sale_icon1"},
                             @{@"name":@"居家照料", @"icon":@"sale_icon2"},
                             @{@"name":@"健康服务", @"icon":@"sale_icon3"},
                             @{@"name":@"特殊食品", @"icon":@"sale_icon4"},
                             @{@"name":@"居家检测", @"icon":@"sale_icon5"},
                             @{@"name":@"医药上门", @"icon":@"sale_icon6"},
                             @{@"name":@"康复辅具", @"icon":@"sale_icon7"},
                             @{@"name":@"全部分类", @"icon":@"sale_icon8"}];
    NSMutableArray *itemArr = [NSMutableArray array];
    
    NSInteger i = 0;
    for (NSDictionary *img in itemImgList) {
        
        QMUIButton *btn = [[QMUIButton alloc] init];
        btn.imagePosition = QMUIButtonImagePositionTop;// 将图片位置改为在文字下方
        btn.tintColorAdjustsTitleAndImage = UIColor.blackColor;
        btn.adjustsImageTintColorAutomatically = NO;
        btn.spacingBetweenImageAndTitle = 10;
        [btn setImage:UIImageMake(img[@"icon"]) forState:UIControlStateNormal];
        [btn setTitle:img[@"name"] forState:UIControlStateNormal];
        btn.titleLabel.font = DYFont(15);
        btn.tag = 20 + i;
        [serviceWarp addSubview:btn];
        [btn addTarget:self action:@selector(serverClick:) forControlEvents:UIControlEventTouchUpInside];

        btn.sd_layout
        .heightIs(74);
        [itemArr addObject:btn];
        i++;
    }
    
    itemWarp.sd_layout
    .topSpaceToView(contentView, 13)
    .leftSpaceToView(contentView, 15)
    .rightSpaceToView(contentView, 15)
    .heightIs(193);
    
    serviceWarp.sd_layout
    .topSpaceToView(itemWarp, 15)
    .rightSpaceToView(itemWarp, 0)
    .leftSpaceToView(itemWarp, 0)
    .bottomSpaceToView(itemWarp, 15);

    [serviceWarp setupAutoWidthFlowItems:itemArr withPerRowItemsCount:4 verticalMargin:15 horizontalMargin:0 verticalEdgeInset:0 horizontalEdgeInset:0];
        
    // 绿色通道
    UIImageView *green = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"home_green_way")];
    green.contentMode = UIViewContentModeScaleAspectFill;
    green.layer.cornerRadius = 10;
    green.layer.masksToBounds = YES;
    green.clipsToBounds = YES;
    [contentView addSubview:green];
    
    green.sd_layout
    .topSpaceToView(itemWarp, 15)
    .rightSpaceToView(contentView, 15)
    .leftSpaceToView(contentView, 15)
    .heightIs(80);
    
    
    // 热门推荐
    UILabel *recomLb = [UILabel new];
    recomLb.text = @"热门推荐";
    recomLb.font = DYFont(21);
    [contentView addSubview:recomLb];
    
    [recomLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(green.mas_bottom).mas_offset(15);
        make.left.equalTo(contentView).mas_offset(15);
    }];

    [contentView setupAutoHeightWithBottomView:recomLb bottomMargin:15];
}

- (void)initConllectionView {

    ULBCollectionViewFlowLayout *flow = [[ULBCollectionViewFlowLayout alloc] init];
    flow.minimumLineSpacing = 15; // 行间距
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flow];
    [_collectionView startInteractiveTransitionToCollectionViewLayout:flow completion:^(BOOL completed, BOOL finished) {
        
    }];
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    [self.view addSubview:_collectionView];
    
    _collectionView.sd_layout
    .topSpaceToView(_hotView, 0)
    .rightEqualToView(self.view)
    .leftEqualToView(self.view)
    .bottomEqualToView(self.view);
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.textColor = KWhiteColor;
    _collectionView.mj_header = header;

        //注册
    //    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellReuseIdentify];
    [_collectionView registerNib:[UINib nibWithNibName:@"HEHotRecomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:CellHotRecomId];
    //UICollectionElementKindSectionHeader注册是固定的
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:SupplementaryViewHeaderIdentify];
    //    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:CellHotRecomId];
}

#pragma mark - load data
- (void)headerRereshing {
    [self loadHotKey];
    [self loadGoodsData];
    [self loadDrugsUrl];
}

- (void)loadHotKey {
    
    HEPageRequest *request = [[HEPageRequest alloc] init];
    request.pageSize = 10;
    [WOAFNetWorkingHandle GETWithBaseUrl:KServerUrl suffixUrl:KHotKey parameters:request success:^(id  _Nonnull responseObject) {
        HEArrayResponse *response = [HEArrayResponse mj_objectWithKeyValues:responseObject];
        [self.hotKeys addObjectsFromArray:[HEHotKeyModel mj_objectArrayWithKeyValuesArray:response.data]];
        [self initHotView];
     } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)loadGoodsData {
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:[NSNumber numberWithInteger:1] forKey:@"pageNum"];
    [params setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
    [params setObject:[NSNumber numberWithInteger:1] forKey:@"recommandStatus"];

    [self.goodsArr removeAllObjects];
    [WOAFNetWorkingHandle GETWithBaseUrl:KServerUrl suffixUrl:KGoodsList parameters:params success:^(id  _Nonnull responseObject) {
        
        NSLog(@"response：  %@", [responseObject mj_JSONString]);

        HEMallPageResponse *response = [HEMallPageResponse mj_objectWithKeyValues:responseObject];
        [self.goodsArr addObjectsFromArray:[HEGoodsModel mj_objectArrayWithKeyValuesArray:response.data.records]];
        [self.collectionView reloadData];
        
        [self.collectionView.mj_header endRefreshing];
        
     } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)loadDrugsUrl {
    [WOAFNetWorkingHandle POSTWithBaseUrl:KServerUrl suffixUrl:KdrugsUrl parameters:@{} success:^(id  _Nonnull responseObject) {
        HEObjectDataResponse *response = [HEObjectDataResponse mj_objectWithKeyValues:responseObject];
        self.drugsUrl = response.data;
    } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)loadCartData {
    [WOAFNetWorkingHandle GETNoHUDWithBaseUrl:KServerUrl suffixUrl:KCartLits parameters:@{} success:^(id  _Nonnull responseObject) {
        NSLog(@"response：  %@", [responseObject mj_JSONString]);

        HEResponse *response = [HEResponse mj_objectWithKeyValues:responseObject];
        HECartDataModel *model = [HECartDataModel mj_objectWithKeyValues:response.data];
        [self setupbadge: model.cartTotal.goodsCount];
    } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)setupbadge:(NSInteger)num {
    if (num == 0) {
        return;
    }
    NSString *str = @"";
    if (num > 99) {
        str = @"99+";
    }else {
        str = [NSString stringWithFormat:@"%ld", num];
    }
    
    [_cartView pp_setBadgeHeight:22];
    _cartView.badgeView.font = DYBlodFont(14);
    
     _cartView.badgeView.qmui_borderPosition = QMUIViewBorderPositionBottom | QMUIViewBorderPositionTop | QMUIViewBorderPositionLeft | QMUIViewBorderPositionRight;
    _cartView.badgeView.qmui_borderWidth = 2;
    _cartView.badgeView.qmui_borderColor = KWhiteColor;
    
    [_cartView pp_addBadgeWithText:str];
    [_cartView pp_moveBadgeWithX:-30 Y:23];
}

#pragma mark -

- (NSMutableArray *)hotKeys {
    if (!_hotKeys) {
        _hotKeys = [NSMutableArray array];
    }
    return _hotKeys;
}

- (NSMutableArray<HEGoodsModel *> *)goodsArr {
    if (!_goodsArr) {
        _goodsArr = [NSMutableArray array];
    }
    return _goodsArr;
}


- (void)searchClickhandler {    
    HEGoodSearchViewController *vc = [[HEGoodSearchViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - delegate

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return NO;
}


#pragma mark - UICollectionViewDataSource method
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.goodsArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HEHotRecomCell *cell = (HEHotRecomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellHotRecomId forIndexPath:indexPath];
    cell.model = self.goodsArr[indexPath.item];
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if([kind isEqualToString:UICollectionElementKindSectionHeader]){
        UICollectionReusableView *supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:SupplementaryViewHeaderIdentify forIndexPath:indexPath];
 
        if (!_hasCreateHead) {
            [self initHeadView:supplementaryView];
        }
        return supplementaryView;
    }
    else if([kind isEqualToString:UICollectionElementKindSectionFooter]) {
//        UICollectionReusableView *supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:SupplementaryViewFooterIdentify forIndexPath:indexPath];
//        supplementaryView.backgroundColor = [UIColor redColor];
//        return supplementaryView;
    }
    return nil;
}

#pragma mark - UICollectionViewDelegate method
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
 
}

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
 
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HEGoodsDetailsViewController *vc = [[HEGoodsDetailsViewController alloc] init];
    vc.goodsId = self.goodsArr[indexPath.item].id;
    [self.navigationController pushViewController:vc animated:YES];
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
    if ([NSStringFromSelector(action) isEqualToString:@"copy:"]
        || [NSStringFromSelector(action) isEqualToString:@"paste:"])
        return YES;
    return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
    NSLog(@"复制之后，可以插入一个新的cell");
}


#pragma mark - UICollectionViewDelegateFlowLayout method
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    return CGSizeMake(KScreenWidth, 435);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(15, 15, 15, 15);//分别为上、左、下、右
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((KScreenWidth-45)/2.0, 246);
    
}
- (UIColor *)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout colorForSectionAtIndex:(NSInteger)section {
    return KHexColor(@"F8F8F8");
}

@end
